# coding:utf-8
# author:frank
# date:2024/12/31
import pygame

pygame.init()

win_w=500
win_h=600
win = pygame.display.set_mode((win_w,win_h))
pygame.display.set_caption("动画应用")
win.fill('white')
pygame.display.flip()
r = 20
y = 50
x = win_w/2
pygame.draw.circle(win,'red',(x,y),r)
pygame.display.update()
i = 0
y_speed = 1
x_speed = 1
while True:
    i +=1
    if i==100:
        y+=0.2 * y_speed
        x+=0.1 * x_speed
        # 清理屏幕(重新刷白)
        win.fill('white')
        # 边界判断
        if y>=win_h-r or y<=r:
            y_speed *=-1
        if x>=win_w-r or x<=r:
            x_speed *=-1
        pygame.draw.circle(win, 'red', (x, y), r)
        pygame.display.update()
        i=0
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()